//
//  CLCycleCollectionViewController.m
//  Charles
//
//  Created by Leo on 2017/7/14.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLCycleCollectionViewController.h"
#import "CLCollectionView.h"
#import "CLCollectionViewController.h"
#import "CLCollectionViewFlowLayout.h"
#import "CLCycleCollectionView.h"

@interface CLCycleCollectionViewController ()<CLCycleCollectionViewDataSource> {
    CLCycleCollectionView *_cycleCollectionView;
    NSArray *_dataArray;
}

@end

@implementation CLCycleCollectionViewController

- (void)dealloc
{
    NSLog(@"AAAAAAA-----------");
    [_cycleCollectionView removeTimer];
    _cycleCollectionView = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    
    CLCollectionViewFlowLayout *layOut = [[CLCollectionViewFlowLayout alloc]init];
    layOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layOut.minimumLineSpacing = 10;
    CGFloat width = self.view.bounds.size.width - 100;
    layOut.itemSize = CGSizeMake(width, 200);
    _cycleCollectionView = [[CLCycleCollectionView alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 200) flowlayOut:layOut class:[CLCollectionViewCell class] identifier:@"collection_id"];
    _cycleCollectionView.dataSource = self;
    _cycleCollectionView.isAutoScroll = YES;
    _cycleCollectionView.isShowPageControl = YES;
    [self.view addSubview:_cycleCollectionView];

    
    _dataArray = @[@"第1页",@"第2页",@"第3页",@"第4页",@"第5页"];
    [_cycleCollectionView setDataArray:_dataArray];
    _cycleCollectionView.backgroundColor = [UIColor clearColor];
    
    UICollectionViewFlowLayout *layOut2 = [[UICollectionViewFlowLayout alloc]init];
    layOut2.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layOut2.minimumLineSpacing = 0;
    layOut2.itemSize = CGSizeMake(SCREEN_WIDTH - 40, 200);
    _cycleCollectionView = [[CLCycleCollectionView alloc]initWithFrame:CGRectMake(20, 100 + 200 + 30, SCREEN_WIDTH - 40, 200) flowlayOut:layOut2 class:[CLCollectionViewCell class] identifier:@"collection_id"];
    _cycleCollectionView.dataSource = self;
    _cycleCollectionView.isAutoScroll = YES;
    _cycleCollectionView.isShowPageControl = YES;
    [_cycleCollectionView setPageEnable:YES];
    [self.view addSubview:_cycleCollectionView];
    _dataArray = @[@"第1页",@"第2页",@"第3页",@"第4页",@"第5页"];
    [_cycleCollectionView setDataArray:_dataArray];
    _cycleCollectionView.backgroundColor = [UIColor clearColor];

}

- (UICollectionViewCell *)clCycleCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CLCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection_id" forIndexPath:indexPath];
    NSArray *indexArray = [_cycleCollectionView indexArray];
    if (indexPath.row < indexArray.count) {
        NSInteger index = [indexArray[indexPath.row] integerValue];
        cell.imageView.image = [UIImage imageNamed:@"timg.jpg"];
        if (index < _dataArray.count) {
            cell.indexLabel.text = _dataArray[index];
            cell.indexLabel.textAlignment = NSTextAlignmentCenter;
        }
    }
    return cell;
}


@end
